feat: implement batch sentiment analysis and add batch endpoint#26
feat: implement batch sentiment analysis and add batch endpoint#26osamaa004 wants to merge 6 commits intoruxailab:mainfrom
Conversation
BasmaElhoseny01
left a comment
There was a problem hiding this comment.
First you need to fix conflicts
Re Check PR to only change files required to be changed for this PR for example no need for changing comments or variable names in non related files
There was a problem hiding this comment.
why did u modify in this file?
There was a problem hiding this comment.
According to my understanding of the issue, I modified bertweet_model.py to implement Tensor-based batching directly within the model's forward pass.
Handling batches at the model level (using padding=True and truncation=True) leverages PyTorch's parallelism, making inference significantly faster than looping over strings. I've also ensured the method remains backward-compatible, so it still works perfectly for single strings (as it used to) while supporting lists of strings.
Regarding the logs, I've removed the initial debug logs to keep the PR focused and clean.
There was a problem hiding this comment.
same why did u changed in this file ?
There was a problem hiding this comment.
I modified the Service Layer to ensure compatibility with the new batch processing logic in the model. Since the model now returns a list of dictionaries instead of a single result, the Service Layer needed to be Type-Aware."
I implemented two main things there:
Handling Polymorphism: I used isinstance() to check if the input is a single string or a list. This keeps the API backward compatible, meaning it still works perfectly for single requests.
Standardizing the Response by using a list comprehension to call format_response, I ensured that the output format remains consistent and clean, whether the user sends one sentence or a many.
There was a problem hiding this comment.
Oops I’ve already cleaned up the .gitignore and reverted those unnecessary changes
a5278a1 to
5d0b214
Compare
|
To verify everything is working perfectly, I ran the entire repository locally using one of the existing videos from the samples/ directory. Here are the results showing the batch inference in actions. 2026-03-21.05-32-21.mp42026-03-21.05-31-16.mp4Please let me know if you have any further feedback or suggestions for additional improvements. I'm looking forward to your guidance. |
Overview:
This PR adds support for batch processing in the sentiment analysis service. It introduces a new endpoint /sentiment/analyze/batch that accepts a list of strings, optimizing performance by reducing inference overhead.
Key Changes:
Created BatchSentimentRequest schema for list-based inputs.
Implemented batch inference logic in SentimentService.
Verified integration with the audio transcription workflow.
Testing:
Tested via Swagger UI with multiple text inputs. Received 200 OK with correct sentiment labels and confidence scores.
Closes #10